#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e6 + 10;
struct node
{
    int l;
    int r;
}a[N];
int n;
bool cmp(node& s1, node& s2)
{
    return s1.l < s2.l;
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].l >> a[i].r;
    }
    sort(a + 1, a + 1 + n, cmp);
    int ret = 1;
    int r = a[1].r;
    for (int i = 1; i <= n; i++)
    {
        int left = a[i].l;
        int right = a[i].r;
        if (left < r)
        {
            r = min(r, right);
        }
        else
        {
            ret++;
            r = right;
        }
    }
    cout << ret << endl;
    return 0;
}